<template>
  <div class="psycholog_school">
    <navigate>心理学堂</navigate>
    <div class="school_cont">
      <div class="recommend_box white_box">
        <div class="dis_flex">
          <img src="@/assets/images/function/blue_hot.png" alt="" class="recommend_img" />
          <div class="recommend_tit">推荐热门心理课程</div>
        </div>

        <div class="hot_box" v-for="(item, index) in hotCourseList" :key="index">
          <img :src="item.cover" alt="" class="carousel_img">
          <div class="recommend_theme">
            主题：{{ item.name }}
          </div>
          <div class="dis_flex just_cont_spa_bet">
            <div class="course_progress">
              <div class="course_author">课程作者：{{ item.editor }}</div>
              <div>我已学习：{{ item.learning_num }}/{{ item.chapter_count }}</div>
            </div>
            <div class="dis_flex">
              <div class="collect_btn item_btn dis_flex just_cont_center" @click="toCollect(item)">
                <img src="@/assets/images/function/star_collect.png" alt="" class="btn_img" v-if="item.is_collect == 0"
                  @click="toCollect(item)" />
                <img src="@/assets/images/function/blue_star_collect.png" alt="" class="btn_img" v-else />
                <div class="btn_txt">收藏课程</div>
              </div>
              <div class="study_btn item_btn dis_flex just_cont_center" @click="checkCourseDetails(item)">
                <img src="@/assets/images/function/courseware.png" alt="" class="btn_img" />
                <div class="btn_txt">学习课件</div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div>
        <div class="head_label dis_flex">
          <img src="@/assets/images/common/bar.png" alt="" class="label_img" />
          <div class="label_txt">所有课程列表</div>
        </div>
        <div class="white_box">
          <div class="course_list">
            <div class="dis_flex">
              <searchInput type="text" v-model="formData.courseName" placeholder="搜索课程名称" @input="handleSearch">
              </searchInput>
              <img src="@/assets/images/evaluate/filtrate_icon.png" alt="" class="search_img"
                @click="isShowFilterPop = true" />
            </div>
            <div class="item_course dis_flex" v-for="(item, index) in courseList" :key="index"
              @click="checkCourseDetails(item)">
              <img :src="item.cover" alt="" class="course_img" />
              <div class="item_info">
                <div class="item_tit">
                  {{ item.name }}
                </div>
                <div class="item_progress">我已学习：{{ item.learning_num }}/{{ item.chapter_count }}</div>
                <div class="item_author">课程作者：{{ item.editor }}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="no_data_txt">-- 无更多心里课程了 --</div>
      </div>
    </div>

    <filterPop :isShowFilterPop="isShowFilterPop" @getFilterData="getFilterData" />
  </div>
</template>


<script>
import searchInput from "@/components/searchInput/index.vue";
import filterPop from "./components/filterPop.vue";
import { queryCourseList, queryHotCourse, collectCourse } from '@/api/funcation/psychologySchool'
export default {
  data() {
    return {
      isShowFilterPop: false,
      courseList: [],
      hotCourseList: [],
      formData: {
        pageSize: 10,
        page: 1,
        courseName: ''
      }
    };
  },
  components: {
    searchInput,
    filterPop,
  },
  created() {
    this.getCourseList()
    this.getHotCourse()
  },
  methods: {
    //热门课程
    async getHotCourse() {
      let { data } = await queryHotCourse()
      this.hotCourseList = data
    },
    //课程列表
    async getCourseList() {
      let par = {
        pageSize: this.formData.pageSize,
        page: this.formData.page,
        name: this.formData.courseName,
        is_learning: this.formData.is_learning,
        is_collect: this.formData.is_collect
      }
      let { data } = await queryCourseList(par)
      this.courseList = data.data
    },
    //筛选信息
    getFilterData(val) {
      this.isShowFilterPop = false
      this.formData = {
        ...this.formData,
        ...val
      }
      this.getCourseList()
    },
    //搜索
    async handleSearch(val) {
      this.formData.courseName = val
      this.getCourseList()
    },
    //收藏课件 
    async toCollect(item) {
      let par = {
        id: item.id,
        status: item.is_collect == 1 ? 0 : 1
      }
      let res = await collectCourse(par)
      if (res.code == 200) {
        this.$toast.success("操作成功！");
        this.getHotCourse()
      }
    },
    //详情
    checkCourseDetails(item) {
      this.$router.push(`/courseDetails?id=${item.id}`)
    },
  }
};
</script>

<style lang="less" scoped>
.white_box {
  background: #ffffff;
  border-radius: 6.67px;
}

.dis_flex {
  display: flex;
  align-items: center;
}

.just_cont_spa_bet {
  justify-content: space-between;
}

.just_cont_center {
  justify-content: center;
}

.psycholog_school {
  background-color: #f4f6fa;
  color: #333333;
}

.school_cont {
  padding: 10px 10px 0 10px;
}

//心里课程
.recommend_box {
  padding: 13px 6.67px 15px 6.67px;
}

.recommend_img {
  width: 14px;
  height: 16.67px;
  margin-right: 10.33px;
}

.recommend_tit {
  font-weight: 700;
  color: #00aeff;
  font-size: 16.67px;
  line-height: 16.67px;
}

.hot_box {
  margin-top: 14px;
}

.carousel_img {
  width: 100%;
  height: 180px;
}

.recommend_theme {
  color: #222222;
  line-height: 21.33px;
  font-size: 15.33px;
  margin: 12.67px 0 14.33px;
}

.course_progress {
  color: #555555;
  font-size: 12px;
  line-height: 12px;
}

.course_author {
  margin-bottom: 8.67px;
}

.item_btn {
  width: 88.33px;
  height: 36.67px;
  text-align: center;
  border-radius: 6.67px;
}

.collect_btn {
  background: #ffffff;
  border: 0.33px solid #dddddd;
  margin-right: 6.67px;
}

.study_btn {
  color: #fff;
  background: linear-gradient(0deg, #ffffff -20%, rgba(255, 255, 255, 0) 20%),
    #0aa7f4;
}

.btn_img {
  width: 12.67px;
  height: 12.67px;
  margin-right: 5.33px;
}

.btn_txt {
  font-size: 12.67px;
}

.head_label {
  margin: 19px 0;
}

.label_img {
  width: 5.33px;
  height: 15.33px;
  margin-right: 11.33px;
}

.label_txt {
  font-weight: bold;
  font-size: 14.67px;
  line-height: 14.67px;
}

.course_list {
  padding: 10px;
}

.search_input {
  width: 280px;
  height: 33.33px;
  margin: 0;
}

.search_img {
  width: 15px;
  height: 16.67px;
  margin-left: 16px;
}

.item_course {
  padding: 10px 0;
  border-bottom: 0.33px solid rgba(85, 85, 85, 0.2);

  &:last-child {
    border: 0;
    padding-bottom: 0;
  }
}

.item_info {
  flex: 1;
  min-width: 0;
}

.course_img {
  width: 130.33px;
  height: 73.33px;
  margin-right: 10.67px;
}

.item_tit {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #222222;
  line-height: 14.67px;
  font-size: 14.67px;
}

.item_progress {
  margin: 18.67px 0 9.33px;
}

.item_author,
.item_progress {
  font-size: 10.67px;
  color: #777777;
}

.no_data_txt {
  margin: 33.33px 0;
  font-size: 10.67px;
  color: #555555;
  text-align: center;
}
</style>